﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing.plaf.basic {
    import org.aswing.*;
    import flash.filters.*;
    import org.aswing.geom.*;
    import org.aswing.plaf.*;
    import flash.text.*;
    import org.aswing.graphics.*;

    public class BasicLabelUI extends BaseComponentUI {

        private static var viewRect:IntRectangle = new IntRectangle();
        private static var textRect:IntRectangle = new IntRectangle();
        private static var iconRect:IntRectangle = new IntRectangle();

        protected var label:JLabel;
        protected var textField:TextField;

        protected function getPropertyPrefix():String{
            return ("Label.");
        }
        override public function installUI(_arg1:Component):void{
            this.label = JLabel(_arg1);
            this.installDefaults(this.label);
            this.installComponents(this.label);
            this.installListeners(this.label);
        }
        override public function uninstallUI(_arg1:Component):void{
            this.label = JLabel(_arg1);
            this.uninstallDefaults(this.label);
            this.uninstallComponents(this.label);
            this.uninstallListeners(this.label);
        }
        protected function installDefaults(_arg1:JLabel):void{
            var _local2:String = this.getPropertyPrefix();
            LookAndFeel.installColorsAndFont(_arg1, _local2);
            LookAndFeel.installBorderAndBFDecorators(_arg1, _local2);
            LookAndFeel.installBasicProperties(_arg1, _local2);
        }
        protected function uninstallDefaults(_arg1:JLabel):void{
            LookAndFeel.uninstallBorderAndBFDecorators(_arg1);
        }
        protected function installComponents(_arg1:JLabel):void{
            this.textField = new TextField();
            this.textField.autoSize = TextFieldAutoSize.LEFT;
            this.textField.selectable = false;
            this.textField.mouseEnabled = false;
            this.textField.mouseWheelEnabled = false;
            _arg1.addChild(this.textField);
            _arg1.setFontValidated(false);
        }
        protected function uninstallComponents(_arg1:JLabel):void{
            _arg1.removeChild(this.textField);
        }
        protected function installListeners(_arg1:JLabel):void{
        }
        protected function uninstallListeners(_arg1:JLabel):void{
        }
        override public function paint(_arg1:Component, _arg2:Graphics2D, _arg3:IntRectangle):void{
            super.paint(_arg1, _arg2, _arg3);
            var _local4:JLabel = JLabel(_arg1);
            viewRect.setRect(_arg3);
            textRect.x = (textRect.y = (textRect.width = (textRect.height = 0)));
            iconRect.x = (iconRect.y = (iconRect.width = (iconRect.height = 0)));
            var _local5:String = AsWingUtils.layoutCompoundLabel(_arg1, _arg1.getFont(), _local4.getText(), this.getIconToLayout(), _local4.getVerticalAlignment(), _local4.getHorizontalAlignment(), _local4.getVerticalTextPosition(), _local4.getHorizontalTextPosition(), viewRect, iconRect, textRect, ((_local4.getText() == null)) ? 0 : _local4.getIconTextGap());
            this.paintIcon(_local4, _arg2, iconRect);
            if (((!((_local5 == null))) && (!((_local5 == ""))))){
                this.textField.visible = true;
                this.paintText(_local4, textRect, _local5);
            } else {
                this.textField.text = "";
                this.textField.visible = false;
            };
            this.textField.selectable = _local4.isSelectable();
            this.textField.mouseEnabled = _local4.isSelectable();
        }
        protected function getIconToLayout():Icon{
            return (this.label.getIcon());
        }
        protected function paintText(_arg1:JLabel, _arg2:IntRectangle, _arg3:String):void{
            var _local4:ASFont = _arg1.getFont();
            if (this.textField.text != _arg3){
                this.textField.text = _arg3;
            };
            if (!_arg1.isFontValidated()){
                AsWingUtils.applyTextFont(this.textField, _local4);
                _arg1.setFontValidated(true);
            };
            AsWingUtils.applyTextColor(this.textField, _arg1.getForeground());
            this.textField.x = _arg2.x;
            this.textField.y = _arg2.y;
            if (!_arg1.isEnabled()){
                _arg1.filters = [new BlurFilter(2, 2, 2)];
            } else {
                _arg1.filters = null;
            };
            this.textField.filters = this.label.getTextFilters();
        }
        protected function paintIcon(_arg1:JLabel, _arg2:Graphics2D, _arg3:IntRectangle):void{
            var _local8:Icon;
            var _local4:Icon = _arg1.getIcon();
            var _local5:Icon;
            var _local6:Array = this.getIcons();
            var _local7:int;
            while (_local7 < _local6.length) {
                _local8 = _local6[_local7];
                this.setIconVisible(_local8, false);
                _local7++;
            };
            if (_local4 == null){
                return;
            };
            if (!_arg1.isEnabled()){
                _local5 = _arg1.getDisabledIcon();
            };
            if (_local5 != null){
                _local4 = _local5;
            };
            this.setIconVisible(_local4, true);
            _local4.updateIcon(_arg1, _arg2, _arg3.x, _arg3.y);
        }
        private function setIconVisible(_arg1:Icon, _arg2:Boolean):void{
            if (_arg1.getDisplay(this.label) != null){
                _arg1.getDisplay(this.label).visible = _arg2;
            };
        }
        protected function getIcons():Array{
            var _local1:Array = new Array();
            if (this.label.getIcon() != null){
                _local1.push(this.label.getIcon());
            };
            if (this.label.getDisabledIcon() != null){
                _local1.push(this.label.getDisabledIcon());
            };
            return (_local1);
        }
        protected function getLabelPreferredSize(_arg1:JLabel, _arg2:Icon, _arg3:String):IntDimension{
            var _local4:IntDimension;
            var _local5:IntRectangle;
            viewRect.setRectXYWH(0, 0, 100000, 100000);
            textRect.x = (textRect.y = (textRect.width = (textRect.height = 0)));
            iconRect.x = (iconRect.y = (iconRect.width = (iconRect.height = 0)));
            AsWingUtils.layoutCompoundLabel(_arg1, _arg1.getFont(), _arg3, _arg2, _arg1.getVerticalAlignment(), _arg1.getHorizontalAlignment(), _arg1.getVerticalTextPosition(), _arg1.getHorizontalTextPosition(), viewRect, iconRect, textRect, ((_arg1.getText() == null)) ? 0 : _arg1.getIconTextGap());
            if (_arg2 == null){
                _local4 = textRect.getSize();
            } else {
                if ((((_arg1.getText() == null)) || ((_arg1.getText() == "")))){
                    _local4 = iconRect.getSize();
                } else {
                    _local5 = iconRect.union(textRect);
                    _local4 = _local5.getSize();
                };
            };
            _local4 = _arg1.getInsets().getOutsideSize(_local4);
            return (_local4);
        }
        override public function getPreferredSize(_arg1:Component):IntDimension{
            var _local2:JLabel = JLabel(_arg1);
            return (this.getLabelPreferredSize(_local2, this.getIconToLayout(), _local2.getText()));
        }
        override public function getMinimumSize(_arg1:Component):IntDimension{
            return (_arg1.getInsets().getOutsideSize());
        }
        override public function getMaximumSize(_arg1:Component):IntDimension{
            return (IntDimension.createBigDimension());
        }

    }
}//package org.aswing.plaf.basic 
